﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Arizu.Repository;
using System.Web.SessionState;
using System.Data;
using Arizu.Entity;

namespace AiRiZu.User.handler
{
    public class UpdatePayoutInfo : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Session["logId"] == null)
            {
                return;
            }

            AirizuPayout airizuPayout = AirizuPayout.CreateInstance();

            PayoutInfoEntity payoutInfoEntity = new PayoutInfoEntity();
            if (context.Request.Params["AccountIDKey"] != null)
            {
                payoutInfoEntity.AccountID = context.Request.Params["AccountIDKey"].ToString();
            }
            else
            {
                payoutInfoEntity.AccountID = "";
            }
            if (context.Request.Params["BankAccountNameKey"] != null)
            {
                payoutInfoEntity.BankAccountName = context.Request.Params["BankAccountNameKey"].ToString();
            }
            else
            {
                payoutInfoEntity.BankAccountName = "";
            }
            if (context.Request.Params["BankAccountNumKey"] != null)
            {
                payoutInfoEntity.BankAccountNum = context.Request.Params["BankAccountNumKey"].ToString();
            }
            else
            {
                payoutInfoEntity.BankAccountNum = "";
            }
            if (context.Request.Params["BankAccountSiteKey"] != null)
            {
                payoutInfoEntity.BankAccountSite = context.Request.Params["BankAccountSiteKey"].ToString();
            }
            else
            {
                payoutInfoEntity.BankAccountSite = "";
            }
            if (context.Request.Params["TypeKey"] != null)
            {
                payoutInfoEntity.Type = int.Parse(context.Request.Params["TypeKey"].ToString());
            }
            else
            {
                payoutInfoEntity.Type = -1;
            }
            payoutInfoEntity.UserId = long.Parse(context.Session["logId"].ToString());

            DataTable dt = airizuPayout.GetPayoutInfo(long.Parse(context.Session["logId"].ToString()));

            if (dt.Rows.Count > 0)
            {
                airizuPayout.UpdatPayoutInfo(payoutInfoEntity);
            }
            else
            {
                airizuPayout.InsertPayoutInfo(payoutInfoEntity);
            }

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
